from pywinauto.application import Application
import time

try:
    # 启动记事本应用程序
    app = Application(backend="uia").start("notepad.exe")
    # 等待一段时间确保窗口加载
    time.sleep(2)

    # 查找记事本主窗口
    main_window = app.window(title_re=".* - 记事本")
    main_window.wait("visible")
    main_window.print_control_identifiers()

    # 查找“文件”菜单项
    file_menu = main_window.child_window(title="最大化", control_type="Button")
    file_menu.wait("enabled", timeout=10)
    # 点击“文件”菜单项
    file_menu.click_input()
    time.sleep(2)
    main_window.restore()
    time.sleep(2)
    file_menu = main_window.child_window(title="文本编辑器", control_type="Edit")
    file_menu.set_text("21313213213")



except Exception as e:
    print(f"发生错误: {e}")